import Mock from 'mockjs'

const total = 85

Mock.mock('/api/user/list', 'post', (options) => {
    const { page, pageSize } = JSON.parse(options.body)
    const totalPages = Math.ceil(total / pageSize)

    const list = []
    for (let i = 0; i < pageSize; i++) {
        const id = (page - 1) * pageSize + i + 1
        if (id > total) break

        list.push(Mock.mock({
            id: id,
            name: '@cname',
            gender: '@pick(["男", "女"])',
            age: '@integer(18,60)',
            email: '@email',
            phone: /^1[3456789]\d{9}$/,
            address: '@county(true)',
            createTime: '@datetime("yyyy-MM-dd HH:mm:ss")'
        }))
    }

    return {
        code: 200,
        data: {
            list,
            total,
            page,
            pageSize,
            totalPages
        }
    }
})

// 商品数据模拟类似，这里省略